<?php

namespace App\Admin\Controllers\Goods;

use App\Admin\Repositories\CmcGoodsCategory;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Widgets\Dropdown;
use Dcat\Admin\Layout\Content;
class CmcGoodsCategoryController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new CmcGoodsCategory(), function (Grid $grid) {
            $grid->withBorder();
            $grid->dropColumn('attr_class_name');
            $grid->quickSearch(['category_name', 'attr_class_name']);
            $grid->column('category_name');

            $grid->column('attr_class_name');
            $grid->column('image')->image($server = null, $width=100, $height=120);
            $grid->column('sort');
            $grid->column('is_show', '状态')->switch()->filter(
                Grid\Column\Filter\In::make([
                    0 => '不显示',
                    1 => '显示',
                ])
            );
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('category_id');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new CmcGoodsCategory(), function (Show $show) {
            $show->field('category_id');
            $show->field('category_name');
            $show->field('short_name');
            $show->field('pid');
            $show->field('level');
            $show->field('is_show');
            $show->field('sort');
            $show->field('image');
            $show->field('keywords');
            $show->field('description');
            $show->field('attr_class_id');
            $show->field('attr_class_name');
            $show->field('category_id_1');
            $show->field('category_id_2');
            $show->field('category_id_3');
            $show->field('category_full_name');
            $show->field('image_adv');
            $show->field('commission_rate');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new CmcGoodsCategory(), function (Form $form) {
            $form->display('category_id');
            $form->text('category_name');

            $form->text('attr_class_name');
            $form->text('level');
            $form->text('is_show');
            $form->text('sort');
            $form->image('image');

        });
    }
}
